﻿
using System ;
using System.Windows.Forms ;

using MskEdit.Dxf.Model ;


namespace MskEdit.Dxf.Frontend
{

    public class DxfBlockTreeNode : TreeNode 
    {
        private DxfBlock dxfBlock_ ;
        
        
        public static DxfBlockTreeNode TryFrom( DxfBlock dxfBlock, DxfBlockTreeNode fallbackValue ) {
        
            if ( dxfBlock == null )
                return fallbackValue ;
                
            return new DxfBlockTreeNode( dxfBlock ) ;
        }
        
        
        public DxfBlockTreeNode( DxfBlock dxfBlock ) {
        
            dxfBlock_ = dxfBlock ;
            this.Text = dxfBlock.Name ;
                            
            foreach ( var dxfEntitiy in dxfBlock_.Entities ) {
                
                DxfEntityTreeNode dxfEntitiyTreeNode = DxfEntityTreeNode.TryFrom( dxfEntitiy, null ) ;
                if ( dxfEntitiyTreeNode == null )
                    continue ;
                    
                this.Nodes.Add( dxfEntitiyTreeNode ) ;
            }

        }
    }
}
